package wht.jly.forum.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Past;
import java.io.Serializable;
import java.util.Date;

/**
 * @author lanyangji
 * @date 2019/2/8 19:33
 */
@Data
@Accessors(chain = true)
@Entity
@Table(name = "forum_user")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @NotBlank(message = "用户名不能为空")
    @Length(max = 12, message = "用户名长度不能超过50")
    @Column(length = 50, unique = true)
    private String username;

    @Length(min = 6, max = 100, message = "密码的长度介于6-100位之间")
    private String password;

    @Email(message = "必须是一个标准的邮箱格式")
    private String email;

    @Past(message = "必须是一个过去的时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    /**
     * 性别
     *
     * 1表示男
     * 0表示女
     * 2表示其他
     */
    @Column(length = 1)
    private Integer gender;

    /**
     * 自我描述
     */
    @Length(max = 100000, message = "不能超过10万字")
    @Column(name = "self_desc", length = 100000)
    private String selfDesc;

    @Column(name = "create_time", columnDefinition = "datetime default NOW()")
    private Date createTime;
}
